********************************************************************************
* Preamble, globals, and import
********************************************************************************
clear all

* Change to proper import and export paths on your machine
global import "{path}/data"
global export "{path}/figs"

import delimited "${import}/conjoint_jp.csv"

********************************************************************************
* Define categories
********************************************************************************
* Create categories
gen category = .
	replace category = 1 if diaoyusenkakusovereignty == "China sovereignty" & chinatariff == "Increase 10%"
	replace category = 2 if diaoyusenkakusovereignty == "China sovereignty" & chinatariff == "Increase 20%"
	replace category = 3 if diaoyusenkakusovereignty == "China sovereignty" & chinatariff == "Decrease 10%"
	replace category = 4 if diaoyusenkakusovereignty == "China sovereignty" & chinatariff == "Decrease 20%"
	replace category = 5 if diaoyusenkakusovereignty == "China sovereignty" & japantariff == "Increase 10%"
	replace category = 6 if diaoyusenkakusovereignty == "China sovereignty" & japantariff == "Increase 20%"
	replace category = 7 if diaoyusenkakusovereignty == "China sovereignty" & japantariff == "Decrease 10%"
	replace category = 8 if diaoyusenkakusovereignty == "China sovereignty" & japantariff == "Decrease 20%"
	
	replace category = 9 if diaoyusenkakusovereignty == "Japan sovereignty" & chinatariff == "Increase 10%"
	replace category = 10 if diaoyusenkakusovereignty == "Japan sovereignty" & chinatariff == "Increase 20%"
	replace category = 11 if diaoyusenkakusovereignty == "Japan sovereignty" & chinatariff == "Decrease 10%"
	replace category = 12 if diaoyusenkakusovereignty == "Japan sovereignty" & chinatariff == "Decrease 20%"
	replace category = 13 if diaoyusenkakusovereignty == "Japan sovereignty" & japantariff == "Increase 10%"
	replace category = 14 if diaoyusenkakusovereignty == "Japan sovereignty" & japantariff == "Increase 20%"
	replace category = 15 if diaoyusenkakusovereignty == "Japan sovereignty" & japantariff == "Decrease 10%"
	replace category = 16 if diaoyusenkakusovereignty == "Japan sovereignty" & japantariff == "Decrease 20%"

* Name categories
label define category ////
		1 `" "China" "+10%" "' ////
		2 `" "China" "+20%" "' ////
		3 `" "China" "-10%" "' ////
		4 `" "China" "-20%" "' ////
		5 `" "Japan" "+10%" "' ////
		6 `" "Japan" "+20%" "' ////
		7 `" "Japan" "-10%" "' ////
		8 `" "Japan" "-20%" "' ////
		9 `" "China" "+10%" "' ////
		10 `" "China" "+20%" "' ////
		11 `" "China" "-10%" "' ////
		12 `" "China" "-20%" "' ////
		13 `" "Japan" "+10%" "' ////
		14 `" "Japan" "+20%" "' ////
		15 `" "Japan" "-10%" "' ////
		16 `" "Japan" "-20%" "' ////

label val category category
	
********************************************************************************
* Calculate marginal effects
********************************************************************************
reg chosen i.category, cl(id)
margins category

********************************************************************************
* Plot marginal effects
********************************************************************************
* Sort results
matrix plot = r(table)'

matsort plot 1 "up"

matrix plot = plot'

* Create plot
coefplot (matrix(plot[1,])), ci((plot[5,] plot[6,])) ///
	vertical ///
	scheme(s1color) ylabel(0(.1)1) ///
	xline(8.5, lstyle(grid)) ///
	yline(.5, lstyle(grid))  ///
	text(.9 3 "China sovereignty", place(e)) ///
	text(.9 11 "Japan sovereignty", place(e)) ///
    ytitle("Probability of choosing deal (%)" " ") ///
	xtitle(" " "Trade policy") ///
	xlabel(, labsize(vsmall)) ///
	xsize(7) ysize(3.5) ///
	color(midblue) ciopts(lcolor(gs10))

* Export plot
graph export "${export}/4. mm_sovereignty_japan.pdf", replace
		
